module.exports = function ($resource, $state, $http, $q, FileUploader, $modal, toaster, $stateParams) {
  
	return {
		restrict: 'AE',
		template: require('../views/planningproject.html'),
		replace: true,
		scope: {
			'baseinfo': '=',
			'examineflag' : '='
		},
		link: function (scope, elements, attrs) {
      console.log('项目发大发发');
			scope.type = $stateParams.type;
      var para = {};
      var url = '';
      if (scope.type == '1'){// 主管领导
        url = '/api/as/ggc/reviewPlanning/findLeaderInfoList';
        paras = {
          'project_state' : '5',
          'leader_state' : '0'
        }
      } else if(scope.type == '2'){ //主要领导
        url = '/api/as/ggc/reviewPlanning/findLeadersInfoList';
        paras = {
          'project_state' : '6',
          'leaders_state' : '0'
        }
      }
			/* 分页
			* ========================================= */
			scope.maxSize = 5;             //最多显示多少个按钮
			scope.bigCurrentPage = 1;      //当前页码
      scope.itemsPerPage = 10         //每页显示几条
      scope.obj={};
      scope.d={};
      scope.searchform = {};
      scope.rsarr = [
        {name:'推荐',value:'1'},
        {name:'不推荐',value:'0'}
      ]
			
			scope.getlist = function (state) {
        console.log(state);
        if (scope.type == '1') { // 主管领导
            var para1 = {
              leader_state : state
            }
        } else if (scope.type == '2') {//主要领导
            var para1 = {
              leaders_state : state
            }
        }
        var para = {
          pageNo:scope.bigCurrentPage, 
          pageSize:scope.itemsPerPage,
        }
				para = angular.extend(paras, para,scope.searchform, para1);
				$resource(url, {}, {}).
				save(para,function(res) {
					console.log(para);
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					scope.objs = res.data.results;
					scope.bigTotalItems = res.data.totalRecord;
				})
			};
			
			scope.getlist(); 

			scope.$watch('examineflag', function(){
				scope.getlist();
			}, true)
			
			// scope.getlist(); 

			scope.toinfo= function (info) {
				var modalInstance = $modal.open({
					template: require('../views/project_cognizance_info.html'),
					controller: 'project_cognizance_info',
					size: 'lg',
					resolve: {
						items: function () {
							return info;
            },
            type: function () {
							return scope.type;
            },
					}
				});
				modalInstance.result.then(function (showResult) {	
          scope.examineflag++;
				});
      }
      // 通过
      scope.pass = function(info){
          scope.flag = 'pass';
          var modalInstance = $modal.open({
            template: require('../views/leaderMessage.html'),
            controller: 'leaderMessage',
            size: 'xs',
            resolve: {
              items: function () {
                return info;
              },
              flag: function () {
                return scope.flag;
              },
              type: function () {
                return scope.type;
              }
            }
          });
          modalInstance.result.then(function (showResult) {	
            scope.examineflag++;
          });
      }
      // 驳回
      scope.reject = function(info){
          scope.flag = 'reject';
          var modalInstance = $modal.open({
            template: require('../views/leaderMessage.html'),
            controller: 'leaderMessage',
            size: 'xs',
            resolve: {
              items: function () {
                return info;
              },
              flag: function () {
                return scope.flag;
              },
              type: function () {
                return scope.type;
              }
            }
          });
          modalInstance.result.then(function (showResult) {	
            scope.examineflag++;
          });
      }
      // 淘汰
      scope.eliminate = function(info){
          scope.flag = 'eliminate';
          var modalInstance = $modal.open({
            template: require('../views/leaderMessage.html'),
            controller: 'leaderMessage',
            size: 'xs',
            resolve: {
              items: function () {
                return info;
              },
              flag: function () {
                return scope.flag;
              },
              type: function () {
                return scope.type;
              }
            }
          });
          modalInstance.result.then(function (showResult) {	
            scope.examineflag++;
          });
      }

    }
	}
}